<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of order_o
 *
 * @author b4by
 */
class order_o extends MY_Controller{
	function __construct() {
		parent::__construct();
		$this->load->model('model_order');
		$this->load->model('model_product');
	}
	
	public function index($id='')
	{
		$product = $this->data['product'] = $this->model_product->get_info($id);
//		if($product===FALSE) show_error (lang('product_not_found'));
		$this->data['temp']= 'admin/order_o/index';
		$this->load->view('admin/main',$this->data);
	}
	
	public function read()
	{
		$id = request('id');
		if($id){
			$pagination = pagination_init($this->model_order->get_total(array('product_id'=>$id)), request('p'));
			$orders = $this->model_order->get_list(array(
				'where'	=> array( 'product_id'	=> $id),
				'limit'	=> array($pagination->from,$pagination->limit),
			));
			
			echo json_encode(array(
				'state'	=> 'success',
				'data'	=> $orders,
				'pagination'	=> $pagination,
			));
		}
		else{
			echo json_encode(array(
				'state'	=> 'error',
				'title'	=> lang('error'),
				'message'	=> lang('product_not_found'),
			));
		}
	}
	
	public function confirm()
	{
		
	}
	
	public function cancel()
	{
		
	}
	
}

?>
